#include <iostream>
#include <queue>
using namespace std;
int a[30][30];
int n;
queue<int> q;
bool IsIn(int x, int y){
    return (x>=0 && x<n && y>=0 && y<n);
}

void BFS(int x, int y){
    if(a[x][y] == 0){
        a[x][y] = 2;
        if(IsIn(x+1, y)) q.push(x+1), q.push(y);
        if(IsIn(x-1, y)) q.push(x-1), q.push(y);
        if(IsIn(x, y+1)) q.push(x), q.push(y+1);
        if(IsIn(x, y-1)) q.push(x), q.push(y-1);
        while(!q.empty()){
            int xx = q.front(); q.pop();
            int yy = q.front(); q.pop();
            BFS(xx, yy);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(NULL);
    cin >> n;
    int x1, y1;
    bool flg = false;
    for(int r=0; r<n; r++){
        for(int c=0; c<n; c++){
            cin >> a[r][c];
            if(a[r][c] == 1 && !flg){
                x1 = r; y1 = c;
                flg = true;
            }
        }
    }
    int x = x1+1, y = y1 + 1;
    BFS(x, y);
    for(int r=0; r<n; r++) {
        for (int c=0; c < n-1; c++) {
            cout << a[r][c] << " ";
        }
        cout << a[r][n-1] << "\n";
    }

    
    return 0;
}
